package com.github.base.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.github.base.annotation.SysLog;
import com.github.base.dto.auth.LoginDTO;
import com.github.base.service.AuthService;
import com.github.base.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: base-service
 * @description: 登录认证
 * @author: hui.zhang
 * @date: 2020/2/15 11:19 PM
 **/

@Slf4j
@RestController
@RequestMapping("/auth")
@Tag(name = "认证模块")
@AllArgsConstructor
public class AuthController {
    private final AuthService authService;

    @SaIgnore
    @PostMapping("/login")
    @Operation(summary = "登录")
    @SysLog(module = "认证模块", value = "登陆")
    public Result<SaTokenInfo> token(@Validated @RequestBody LoginDTO loginDTO) {
        SaTokenInfo login = authService.login(loginDTO.getUsername(), loginDTO.getPassword());
        return Result.ok(login);
    }


}
